﻿
@code{
    protected override void OnInitialized()
    {
        base.OnInitialized();

    }
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);
        if (!firstRender) return;
        await 刷新数据();
    }
    private async Task 刷新数据()
    {
        await Task.Delay(1000);
        for (int i = 0; i < 100; i++)
        {
            Items2.Add(new Spec { id = i, Name = "Test04_name" + i });
        }
        await table1.QueryAsync();
    }

}



<Table TItem="Spec"
       IsPagination="true"
       ShowToolbar="true"
       ShowDefaultButtons="false" 
       AutoGenerateColumns="true"
       OnQueryAsync="@OnQueryAsync"
       @ref="@table1">
</Table>

@code{
    Table<Spec> table1;
    private List<Spec>? Items2 { get; set; } = new List<Spec>();

    private Task<QueryData<Spec>> OnQueryAsync(QueryPageOptions options)
    {
        // 设置记录总数
        var total = Items2.Count;

        // 内存分页
        var items = Items2.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList();

        return Task.FromResult(new QueryData<Spec>()
        {
            Items = items,
            TotalCount = total,
            IsSorted = true,
            IsFiltered = true,
            IsSearch = true
        });
    }



}
